package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.pojo.User;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.CatalogCurrentVO;
import com.cskaoyan.bean.vo.CollectAddordeleteVO;
import com.cskaoyan.bean.vo.wx.CollectListVO;
import com.cskaoyan.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("all")
@RestController
@RequestMapping("wx/collect")
public class CollectController {
    @Autowired
    CollectService collectService;

    @RequestMapping("list")
    public BaseRespVo collectList(Integer type, Integer page, Integer size) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        if (user == null) {
            return BaseRespVo.fail("请登录");
        }
        CollectListVO catalogCurrentVO = collectService.collectList(page, size, user.getId());
        return BaseRespVo.ok(catalogCurrentVO, "成功");
    }

    @RequestMapping("addordelete")
    public BaseRespVo collectAddordelete(@RequestBody Map map) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        if (user == null) {
            return BaseRespVo.fail("请登录");
        }
        Integer type = (int)map.get("type");
        Integer valueId = (int)map.get("valueId");
        CollectAddordeleteVO collectAddordeleteVO = collectService.collectAddordelete(type,valueId,user.getId());
        return BaseRespVo.ok(collectAddordeleteVO);
    }

}
